package org.utils.cmdline.parameters;

import java.util.Iterator;

import org.utils.cmdline.CommandBase;
import org.utils.cmdline.GenericCommand;

public class CommandParameter extends CommandBase {

    private boolean required = true;
	private int parameterLength;
    private boolean beingUsed = no();

//accessing
    public int parameterLength() {
	return parameterLength;
    }

    public void parameterLength(int aLength) {
		checkIntegerIsPositive(
			aLength,
		    this.getClass() + " parameterLength(aLength)"
		);
		parameterLength = aLength;
    }

    public boolean beingUsed() {
		return beingUsed;
    }

    protected void startBeingUsed() {
		beingUsed = yes();
    }

//testing
    public boolean isTerminal() {
		return false;
    }

//constants
    public static Object defaultCommand() {
		return "unknown command";
    }

//controlled contruction
    public CommandParameter(int additionalParameterLength) {
		parameterLength(additionalParameterLength);
    }

	public CommandParameter(int additionalParameterLength, boolean pRequired) {
		parameterLength(additionalParameterLength);
		required = pRequired;
	}

//action
    public void loadAdditionalArguments(Iterator iterator) {
		startBeingUsed();
    }

    public void enact(GenericCommand command) {
		if (beingUsed()) {
		    actUpon(command);
		}
    }

    public void actUpon(GenericCommand command) {
    }

	/**
	 * @return boolean
	 */
	public boolean isRequired()
	{
		return required;
	}

	/**
	 * @param b
	 */
	public void setRequired(boolean b)
	{
		required = b;
	}
}

